$(function () {

    //变量抽取
    var billRecord_dataGrid = $("#billRecord_dataGrid");
    var billRecord_dialog = $("#billRecord_dialog");
    var billRecord_form = $("#billRecord_form");

    billRecord_dataGrid.datagrid({
        fitColumns: true,//列自适应
        url: "/billRecord/query.do",
        fit: true,
        columns: [[
            {field: 'sn', title: '保单编号', width: 100},
            {
                field: 'holder', title: '投保人', width: 100, formatter: function (value, row, index) {
                return value ? value.clientName : "";
            }
            },
            {
                field: 'car', title: '车牌号', width: 100, formatter: function (value, row, index) {
                return value ? value.number : "";
            }
            },
            {
                field: 'adate', title: '申请时间', width: 100, formatter: function (value, row, index) {
                return new Date(value).toLocaleDateString();
            }
            },
            {
                field: 'pdate', title: '核保日期', width: 100, formatter: function (value, row, index) {
                return value ? new Date(value).toLocaleDateString() : "";
            }
            },
            {
                field: 'ddate', title: '保险截止日', width: 100, formatter: function (value, row, index) {
                return value ? new Date(value).toLocaleDateString() : "";
            }
            },
            {field: 'year', title: '保险时长(/年)', width: 100},
            {
                field: 'opUser', title: '业务员', width: 100, formatter: function (value, row, index) {
                return value ? value.realname : "";
            }
            },
            {
                field: 'auditor', title: '审核人', width: 100, formatter: function (value, row, index) {
                return value ? value.username : "";
            }
            },
            {field: 'totalAmount', title: '投保总金额', width: 100},
            {
                field: 'state', title: '状态', width: 100, formatter: function (value, row, index) {
                if (value == "拒保") {
                    return "<font style='color: #c9302c'>" + value + "</font>";
                }
                return value;
            }
            },
            {
                field: 'item', title: '查看产品明细', width: 100, formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='showBill()'>查看明细</a>";

            }
            }

        ]],
        toolbar: "#tb",//工具
        pagination: true,//分页
        rownumbers: true,//行号
        singleSelect: true//只允许选择一行
    });

    $("#temOrder_dialog").dialog({
        title: "查看明细",
        width: 600,
        height: 550,
        closed: true
    })

    //方法抽成对象统一管理
    var methodObj = {
        searchForm: function () {
            var clientName = $("#clientName").textbox('getValue');
            var temSn = $("#temSn").textbox('getValue');
            var op_User = $("#op_User").textbox('getValue');
            billRecord_dataGrid.datagrid('load', {
                clientName: clientName,
                temSn: temSn,
                op_User: op_User
            });
        },

        reload: function () {
            billRecord_dataGrid.datagrid("load");
        },
    };

    //按钮统一绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });


});





